<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/directive/ngStyle.js?message=docs(ngStyle)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.3.13/src/ng/directive/ngStyle.js#L3' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">ngStyle</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - directive in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>The <code>ngStyle</code> directive allows you to set CSS style on an HTML element conditionally.</p>

</div>




<div>
  

  
  <h2>Directive Info</h2>
  <ul>
    
    <li>This directive executes at priority level 0.</li>
  </ul>

  
  <h2 id="usage">Usage</h2>
  <div class="usage">
  
    <ul>
    <li>as attribute:
        <pre><code>&lt;ANY&#10;  ng-style=&quot;&quot;&gt;&#10;...&#10;&lt;/ANY&gt;</code></pre>
      </li>
    <li>as CSS class:
        <pre><code>&lt;ANY class=&quot;ng-style: ;&quot;&gt; ... &lt;/ANY&gt;</code></pre>
      </li>
    
  </div>
  
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        ngStyle
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-expression">expression</a>
      </td>
      <td>
        <p><a href="guide/expression">Expression</a> which evals to an
object whose keys are CSS style names and values are corresponding values for those CSS
keys.</p>
<p>Since some CSS style names are not valid keys for an object, they must be quoted.
See the &#39;background-color&#39; style in the example below.</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
  


  
  <h2 id="example">Example</h2><p>

<div>
  <a ng-click="openPlunkr('examples/example-example91', $event)" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>

  <div class="runnable-example"
      path="examples/example-example91">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;input type=&quot;button&quot; value=&quot;set color&quot; ng-click=&quot;myStyle={color:&#39;red&#39;}&quot;&gt;&#10;&lt;input type=&quot;button&quot; value=&quot;set background&quot; ng-click=&quot;myStyle={&#39;background-color&#39;:&#39;blue&#39;}&quot;&gt;&#10;&lt;input type=&quot;button&quot; value=&quot;clear&quot; ng-click=&quot;myStyle={}&quot;&gt;&#10;&lt;br/&gt;&#10;&lt;span ng-style=&quot;myStyle&quot;&gt;Sample Text&lt;/span&gt;&#10;&lt;pre&gt;myStyle={{myStyle}}&lt;/pre&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="style.css"
      language="css"
      type="css">
      <pre><code>span {&#10;  color: black;&#10;}</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="protractor.js"
      type="protractor"
      language="js">
      <pre><code>var colorSpan = element(by.css(&#39;span&#39;));&#10;&#10;it(&#39;should check ng-style&#39;, function() {&#10;  expect(colorSpan.getCssValue(&#39;color&#39;)).toBe(&#39;rgba(0, 0, 0, 1)&#39;);&#10;  element(by.css(&#39;input[value=\&#39;set color\&#39;]&#39;)).click();&#10;  expect(colorSpan.getCssValue(&#39;color&#39;)).toBe(&#39;rgba(255, 0, 0, 1)&#39;);&#10;  element(by.css(&#39;input[value=clear]&#39;)).click();&#10;  expect(colorSpan.getCssValue(&#39;color&#39;)).toBe(&#39;rgba(0, 0, 0, 1)&#39;);&#10;});</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-example91/index.html" name="example-example91"></iframe>
  </div>
</div>


</p>

</div>


